import { Observer } from 'mobx-vue'
import { Component, Vue } from 'vue-property-decorator'
import { login } from 'src/utils/axios'
require('./Login.scss')
@Observer
@Component({})
export default class ZtLogin extends Vue {
    formInline:any = {
        username:"",
        password:""
    };
    ruleInline:any = {
        username: [
            { required: true, message: '请填写用户名', trigger: 'blur' }
        ],
        password: [
            { required: true, message: '请填写密码', trigger: 'blur' },
            { type: 'string', min: 6, message: '密码长度不能小于6位', trigger: 'blur' }
        ]
    };
    mounted() {
       
    }

    async handleSubmit(name) {
        let vm:any = this;
        vm.$refs[name].validate(async (valid) => {
           if (valid) {
                let params:any = {
                    username:vm.formInline.username,
                    password:vm.formInline.password,
                };
                let out:any = await login(params);
                if (!out.status) {
                    window.localStorage.setItem('sessionId',out.data.token);
                    window.localStorage.setItem("nickname", out.data.member.nickname);
                    window.localStorage.setItem("truename", out.data.member.truename);
                    window.localStorage.setItem("avatar", out.data.member.avatar);
                    window.localStorage.setItem("street_code", out.data.member.street_code);
                    vm.$Message.success('提交成功!');
                    vm.$router.push('/check/index');
                }else {
                    vm.$Message.error(await vm.$api.xerror(out.status));
                }
            }
        })
    }

}
